package com.xiao;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class ConsumerApplication {

    public static void main(String[] args) {
        new SpringApplication(ConsumerApplication.class).run(args);
    }

    @RabbitListener(queues = "simple.queue1")
    public void listener1(String msg) throws InterruptedException {
        log.info("queue1=>{}", msg);
    }

    @RabbitListener(queues = "simple.queue2")
    public void listener2(String msg) throws InterruptedException {
        log.error("queue2=>{}", msg);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(name = "direct1.queue1", durable = "true"),
                    exchange = @Exchange(name = "direct1", type = ExchangeTypes.DIRECT),
                    key = {"red", "blue"}
            )
    })
    public void listener3(String msg) throws InterruptedException {
        log.error("queue3=>{}", msg);
    }
}
